﻿using System;
using System.Linq;
using System.Linq.Expressions;
using System.Linq.Dynamic;using System.Text;
using System.Data.Linq;
using System.Transactions;
using LinqToSqlExtensions;using System.ServiceModel;
using System.Collections;
using System.Collections.Generic;
using CardsServer.DAL;

namespace CardsServer.WCF
{
	public partial interface IService
{
[OperationContract]
string whd_d_Add(whd_d model ,int ACID);


[OperationContract]
string whd_d_Update(whd_d model ,int ACID);


[OperationContract]
string whd_dBydid_Delete(int did,int ACID);


[OperationContract]
whd_d whd_dBydid_Get(int did,int ACID );


[OperationContract]
List<whd_d> whd_d_Get(string sortBy,int ACID);




}
public partial class Service : IService
{
#region  添加whd_d表数据
/// <summary>
/// 添加whd_d
/// </summary>
/// <param name="model">whd_d实体</param>
/// <returns>空或错误</returns>
public string whd_d_Add(whd_d model,int ACID)
{
if(model.did==null )
{
return "『外乎单明细ID』不能为空！";
}
if(model.state==null )
{
return "『0=已提数据 1=已补全 2=已打印 3=已反馈  4=已收单 5=已录单』不能为空！";
}
if(string.IsNullOrEmpty(model.ClientName))
{
return "『用户名称』不能为空！";
}
if(string.IsNullOrEmpty(model.pid))
{
return "『外乎单ID』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.whd_d.Count(p=>p.did==model.did)>0)
{
return "主键已存在！";
}
ctx.whd_d.InsertOnSubmit(model);
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 添加失败!错误详细信息：" + ex.Message;
}
}
}
#endregion

#region  添加whd_d表数据事物用重构
/// <summary>
/// 添加whd_d事物用重构
/// </summary>
/// <param name="model">whd_d实体</param>
/// <returns>空或错误</returns>
private string whd_d_Add(whd_d model,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
if(model.did==null )
{
return "『外乎单明细ID』不能为空！";
}
if(model.state==null )
{
return "『0=已提数据 1=已补全 2=已打印 3=已反馈  4=已收单 5=已录单』不能为空！";
}
if(string.IsNullOrEmpty(model.ClientName))
{
return "『用户名称』不能为空！";
}
if(string.IsNullOrEmpty(model.pid))
{
return "『外乎单ID』不能为空！";
}

ctx.whd_d.InsertOnSubmit(model);
return string.Empty;
}
#endregion



#region  修改whd_d表数据
/// <summary>
/// 修改whd_d
/// </summary>
/// <param name="model">whd_d实体</param>
/// <returns>空或错误</returns>
public string whd_d_Update(whd_d model,int ACID)
{
if(model.did==null )
{
return "『外乎单明细ID』不能为空！";
}
if(model.state==null )
{
return "『0=已提数据 1=已补全 2=已打印 3=已反馈  4=已收单 5=已录单』不能为空！";
}
if(string.IsNullOrEmpty(model.ClientName))
{
return "『用户名称』不能为空！";
}
if(string.IsNullOrEmpty(model.pid))
{
return "『外乎单ID』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.whd_d.Count(p=>p.did==model.did)!= 1)
{
return "未找到指定记录或记录不唯一！";
}
whd_d whd_dmodel=ctx.whd_d.Single(p => p.did==model.did);



whd_dmodel.ClientName=model.ClientName;
whd_dmodel.slno=model.slno;
whd_dmodel.wnjf=model.wnjf;
whd_dmodel.jrhye=model.jrhye;
whd_dmodel.Remarks=model.Remarks;
whd_dmodel.address=model.address;
whd_dmodel.DK=model.DK;
whd_dmodel.wntc=model.wntc;
whd_dmodel.thfyxx=model.thfyxx;
whd_dmodel.pdsfyc=model.pdsfyc;
whd_dmodel.fsp=model.fsp;
whd_dmodel.jlxx=model.jlxx;
whd_dmodel.opdate=model.opdate;
whd_dmodel.cust1=model.cust1;
whd_dmodel.cust2=model.cust2;
whd_dmodel.state=model.state;
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 修改失败!错误详细信息：" + ex.Message;
}
}
}
#endregion



#region  删除whd_d表Bydid数据
/// <summary>
/// 删除whd_dBydid
/// </summary>
/// <param name="did">外乎单明细ID</param>
/// <returns>空或错误</returns>
public string whd_dBydid_Delete(int did,int ACID)
{
if(did==null )
{
return "『外乎单明细ID』不能为空！";
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.whd_d.Count(p=>p.did==did)!=1)
{
return null;
}
whd_d model=ctx.whd_d.Single(p => p.did== did);
ctx.whd_d.DeleteOnSubmit(model);
ctx.SubmitChanges();
return string.Empty;
}
catch (Exception ex)
{
return " 删除失败!错误详细信息：" + ex.Message;
}
}
}
#endregion

#region  删除whd_d表Bydid数据[事物用重构]
/// <summary>
/// 删除whd_dBydid[事物用重构]
/// </summary>
/// <param name="did">外乎单明细ID</param>
/// <returns>空或错误</returns>
private string whd_dBydid_Delete(int did,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
if(did==null )
{
return "『外乎单明细ID』不能为空！";
}
if(ctx.whd_d.Count(p=>p.did==did)!=1)
{
return null;
}
whd_d model=ctx.whd_d.Single(p => p.did== did);
ctx.whd_d.DeleteOnSubmit(model);
return string.Empty;
}
#endregion



#region  获取whd_d表Bydid数据
/// <summary>
/// 获取whd_dBydid
/// </summary>
/// <param name="did">外乎单明细ID</param>
/// <returns>当前表</returns>
public whd_d whd_dBydid_Get(int did,int ACID)
{
if(did==null )
{
return null;
}
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if(ctx.whd_d.Count(p=>p.did==did)!=1)
{
return null;
}
return ctx.whd_d.SingleOrDefault(p=>p.did==did);
}
catch (Exception ex)
{
return null;
}
}
}
#endregion



#region  获取whd_d表数据
/// <summary>
/// 获取whd_d
/// </summary>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<whd_d></returns>
public List<whd_d> whd_d_Get(Expression<Func<whd_d, bool>> predicate , string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.whd_d.ToList();
}
 else 
{
return ctx.whd_d.OrderBy(sortBy).ToList();
}
}
else
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.whd_d.Where(predicate).ToList();
}
 else 
{
return ctx.whd_d.Where(predicate).OrderBy(sortBy).ToList();
}
}
}
catch (Exception ex)
{
return null;
}
}
}
#endregion


#region  获取whd_d表数据
/// <summary>
/// 获取whd_d
/// </summary>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<whd_d></returns>
public List<whd_d> whd_d_Get(string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
return whd_d_Get(null,sortBy, ACID);
}
catch (Exception)
{
return null;
}
}
}
#endregion


#region  获取whd_d表数据计数
/// <summary>
/// 获取whd_d表数据计数
/// </summary>
/// <returns>List<whd_d></returns>
public int whd_d_GetCount(Expression<Func<whd_d, bool>> predicate,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
return ctx.whd_d.Count();

}
 else
{
return ctx.whd_d.Where(predicate).Count();
}
}
catch 
{
return 0;
}
}
}
#endregion




#region  获取whd_d分页表数据
/// <summary>
/// 获取whd_d分页表数据
/// </summary>
/// <param name="pageIndex">当前页</param>
/// <param name="pageSize">页大小</param>
/// <param name="sortBy">排序属性名</param>
/// <param name="sortType">排序类型0=升序 1=降序</param>
/// <returns>List<whd_d></returns>
public List<whd_d> whd_d_Getpage(int pageIndex, int pageSize,Expression<Func<whd_d, bool>> predicate ,string sortBy,int ACID)
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
if (predicate == null)
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.whd_d.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
 else 
{
return ctx.whd_d.OrderBy(sortBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
}
else
{
if(string.IsNullOrWhiteSpace(sortBy))
{
return ctx.whd_d.Where(predicate).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
 else 
{
return ctx.whd_d.Where(predicate).OrderBy(sortBy).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
}
}
}
catch (Exception ex)
{
return null;
}
}
}
#endregion


#region  批量修改whd_d表数据
/// <summary>
/// 批量修改whd_d
/// </summary>
/// <param name="predicate">Expression<Func<whd_d, bool>></param> 查找表达式树
/// <param name="updater">Expression<Func<whd_d,whd_d>> 更新表达式树</param>
/// <param name="returns">影响记录数</param>
public int whd_d_batchUpdate(Expression<Func<whd_d, bool>> predicate,Expression<Func<whd_d, whd_d>> updater,int ACID)
{
using (TransactionScope ts=new TransactionScope())
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
int ok = ctx.whd_d.Update(predicate, updater);
ts.Complete();
 return ok;
}
catch (Exception ex)
{
return 0;
}
}
}
}
#endregion


#region  批量修改whd_d表数据事物用重构
/// <summary>
/// 批量修改whd_d事物用重构
/// </summary>
/// <param name="predicate">Expression<Func<whd_d, bool>></param> 查找表达式树
/// <param name="updater">Expression<Func<whd_d,whd_d>> 更新表达式树</param>
/// <param name="ctx">数据上下文</param>
/// <param name="returns">影响记录数</param>
private int whd_d_batchUpdate(Expression<Func<whd_d, bool>> predicate,Expression<Func<whd_d, whd_d>> updater,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
int ok = ctx.whd_d.Update(predicate, updater);
return ok;
}
#endregion


#region  批量删除whd_d表数据
/// <summary>
/// 批量删除whd_d
/// </summary>
/// <param name="predicate">Expression<Func<whd_d, bool>></param> 查找表达式树
/// <param name="returns">影响记录数</param>
public int whd_d_batchDel(Expression<Func<whd_d, bool>> predicate,int ACID)
{
using (TransactionScope ts=new TransactionScope())
{
using(CardsServer.DAL.DataClassesDataContext ctx=new CardsServer.DAL.DataClassesDataContext(getAccConnStr(ACID)))
{
try
{
int ok = ctx.whd_d.Delete(predicate);
ts.Complete();
 return ok;
}
catch (Exception ex)
{
return 0;
}
}
}
}
#endregion


#region  批量删除whd_d表数据事物用重构
/// <summary>
/// 批量删除whd_d事物用重构
/// </summary>
/// <param name="predicate">Expression<Func<whd_d, bool>></param> 查找表达式树
/// <param name="ctx">数据上下文</param>
/// <param name="returns">影响记录数</param>
private int whd_d_batchDel(Expression<Func<whd_d, bool>> predicate,int ACID, CardsServer.DAL.DataClassesDataContext ctx)
{
int ok = ctx.whd_d.Delete(predicate);
return ok;
}
#endregion


}
}

